package com.yuncheng.spcyApi.service.impl;

import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.entity.SpcyKpNdkpBasic;

import com.yuncheng.spcyApi.mapper.SpcyKpNdkpBasicMapper;
import com.yuncheng.spcyApi.service.ISpcyKpNdkpBasicService;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.utils.OrderItemUtils;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import org.springframework.stereotype.Service;

import com.yuncheng.common.base.service.impl.BaseServiceImpl;

/**
 * @Description: 审评查验-年度考核基本表
 * @Author: yuncheng
 * @Date: 2023-03-28
 * @Version: V1.0
 */
@Service
public class SpcyKpNdkpBasicServiceImpl extends BaseServiceImpl<SpcyKpNdkpBasicMapper, SpcyKpNdkpBasic> implements ISpcyKpNdkpBasicService {

    @Override
    public Page<SpcyKpNdkpBasic> selectPageList(SpcyKpNdkpBasic query, PageVo pageVo, OrderItemVo orderItemVo, boolean onlyCurrentUser) {
        Page<SpcyKpNdkpBasic> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        LambdaQueryWrapper<SpcyKpNdkpBasic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(query.getFyear()), SpcyKpNdkpBasic::getFyear, query.getFyear());
        queryWrapper.like(StringUtils.isNotBlank(query.getFndzhkpjg()), SpcyKpNdkpBasic::getFndzhkpjg, query.getFndzhkpjg());

        if (onlyCurrentUser){
            queryWrapper.eq(SpcyKpNdkpBasic::getFuserid, GetCurrentUserUtils.getCurrentUserId());
        }else {
            queryWrapper.eq(StringUtils.isNotBlank(query.getFuserid()), SpcyKpNdkpBasic::getFuserid, query.getFuserid());
        }
        if (StringUtils.isBlank(orderItemVo.getOrderItem())){
            queryWrapper.orderByDesc(SpcyKpNdkpBasic::getFyear);
            queryWrapper.orderByDesc(SpcyKpNdkpBasic::getCreateTime);
        }else {
            OrderItemUtils.setOrderItem(queryWrapper, orderItemVo);
        }
        return page(page, queryWrapper);
    }
}
